package com.example.leetdemo.finash;

public class Solution45 {

    public int jump(int[] nums) {
        int[] dp = new int[nums.length];
        dp[0] = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < Math.min(nums[i] + i + 1, nums.length); j++) {
                dp[j] = dp[j] != 0 ? Math.min(dp[j], dp[i] + 1) : dp[i] + 1;
            }
            if (Math.min(nums[i] + i + 1, nums.length) == nums.length) {
                break;
            }
        }
        return dp[nums.length - 1];
    }

    public static void main(String[] args) {
        Solution45 solution45 = new Solution45();
        solution45.jump(new int[] {2,3,1,1,4});
    }

}
